package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.events.query.SnapshotApplyQuery;
import net.maku.events.vo.SnapshotApplyVO;
import net.maku.events.vo.UserApplyCommentVO;
import net.maku.events.vo.UserSnapshotVO;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.events.convert.ActivitySnapshotConvert;
import net.maku.events.entity.ActivitySnapshotEntity;
import net.maku.events.service.ActivitySnapshotService;
import net.maku.events.query.ActivitySnapshotQuery;
import net.maku.events.vo.ActivitySnapshotVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;


/**
 * 随手拍活动
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@RestController
@RequestMapping("events/activity_snapshot")
@Tag(name = "随手拍活动")
@AllArgsConstructor
public class ActivitySnapshotController {
    private final ActivitySnapshotService activitySnapshotService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:activity_snapshot:page')")
    public Result<PageResult<ActivitySnapshotVO>> page(@ParameterObject @Valid ActivitySnapshotQuery query) {
        PageResult<ActivitySnapshotVO> page = activitySnapshotService.page(query);

        return Result.ok(page);
    }

    @GetMapping("/join/{id}")
    @Operation(summary = "参与活动")
    public Result<String> joinActivity(@PathVariable("id") Long id) {
        activitySnapshotService.joinActivity(id);
        return Result.ok();
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:activity_snapshot:info')")
    public Result<ActivitySnapshotVO> get(@PathVariable("id") Long id) {
        return Result.ok(activitySnapshotService.getInfoById(id));
    }

    @PostMapping
    @Operation(summary = "随手拍活动添加随手拍")
    public Result<Double> save(@RequestBody SnapshotApplyVO vo) {
        return Result.ok( activitySnapshotService.saveUserSnapshot(vo));
    }

    @PostMapping("/look/snapshot")
    @Operation(summary = "查询随手拍")
    public Result<PageResult<UserSnapshotVO>> lookSnapshot(@RequestBody SnapshotApplyQuery query) {
        PageResult<UserSnapshotVO> page = activitySnapshotService.lookSnapshot(query);
        return Result.ok(page);
    }

}